﻿namespace Northwind.ViewModel
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using GalaSoft.MvvmLight;
    using Northwind.Interfaces.Data.Model;
    using System.Collections.ObjectModel;
    using Northwind.Application;

    public class EmployeesViewModel : ViewModelBase
    {
        private ObservableCollection<IEmployeeModel> _employees = null;
        public ObservableCollection<IEmployeeModel> Employees
        {
            get
            {
                if (_employees == null)
                {
                    IEnumerable<IEmployeeModel> employees = Core.Instance.NorthwindManager.GetEmployees();
                    _employees = new ObservableCollection<IEmployeeModel>(employees.Select((employee) => { return new EmployeeViewModel(employee); }));
                }

                return _employees;
            }
        }

        public const string SelectedEmployeePropertyName
        = "SelectedEmployee";

        private IEmployeeModel _selectedEmployee = null;
        public IEmployeeModel SelectedEmployee
        {
            get
            { return _selectedEmployee; }
            set
            {
                if (_selectedEmployee == value)
                {
                    return;
                }
                _selectedEmployee = value;

                RaisePropertyChanged(SelectedEmployeePropertyName);
            }
        }        

    }
}
